//
//  TodayViewController.m
//  timeWidget
//
//  Created by 李志伟 on 2017/5/8.
//  Copyright © 2017年 lee. All rights reserved.
//

#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>

#import "widgetView.h"

@interface TodayViewController () <NCWidgetProviding,UITableViewDelegate,UITableViewDataSource>{
    NSArray *titleArray;
    
    widgetView *widget;
}

@end

@implementation TodayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;
    
    widget = [[widgetView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [self.mainView addSubview:widget];
    
    
    titleArray = @[@"清新简约",@"黝黑夜光",@"典雅商务"];
    UITableView *selectView = [[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.size.width-200, 5, 150, self.mainView.frame.size.height)];
//    selectView.backgroundColor = [UIColor orangeColor];
    selectView.dataSource = self;
    selectView.delegate = self;
    [self.view addSubview:selectView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
    // Perform any setup necessary in order to update the view.
    
    // If an error is encountered, use NCUpdateResultFailed
    // If there's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData

    completionHandler(NCUpdateResultNewData);
}

-(void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize{
//    if (activeDisplayMode == NCWidgetDisplayModeCompact) {
//        NSLog(@"叠起状态下的默认size：%@", NSStringFromCGSize(maxSize));
//        self.preferredContentSize = CGSizeMake(maxSize.width, 110);
//    } else {
//        self.preferredContentSize = CGSizeMake(maxSize.width, 200);
//    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return titleArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CELL"];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.text = titleArray[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:11];
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [widget changeStyle:(int)(indexPath.row)];
}

@end
